package com.hzvdvmc.autosale.base;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.hzvdvmc.autosale.MyApp;

import java.lang.reflect.Method;

/**
 * Created by william on 2017/11/9.
 */

public class BaseActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ((MyApp) getApplication()).addActivity(this);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        //隐藏虚拟按键
    }

    @Override
    protected void onDestroy() {
        ((MyApp) getApplication()).removeActivity(this);
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
        disableStatusBar();
    }

    public void disableStatusBar(){
        Object service = getSystemService("statusbar");
        try {
            Class<?> statusBarManager = Class.forName("android.app.StatusBarManager");
            Method expand = statusBarManager.getMethod("disable", int.class);
            //判断版本大小
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                expand.invoke(service, 0x00010000);
            }else {
                expand.invoke(service, 0x00000001);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
